package logic;

import dao.HorarioDAO;
import dto.HorarioDTO;
import java.sql.SQLException;
import java.time.DayOfWeek;
import java.time.LocalTime;
import java.util.ArrayList;

/**
 *
 * @author rub
 */
public class Horario {

  private int id;
  private int idMedico;
  private DayOfWeek dia;
  private LocalTime horaDesde;
  private LocalTime horaHasta;
  
  public Horario(int id, int idMedico, DayOfWeek day, LocalTime horaDesde, LocalTime horaHasta) {
    this.id = id;
    this.idMedico = idMedico;
    this.dia = day;
    this.horaDesde = horaDesde;
    this.horaHasta = horaHasta;
  }

  public Horario(HorarioDTO dto){
    id = dto.getId();
    idMedico = dto.getIdMedico();
    dia = dto.getDia();
    horaDesde = dto.getHoraDesde();
    horaHasta = dto.getHoraHasta();
  }

  /* not needed?
  public ArrayList<Horario> ListaHorarios(ArrayList<HorarioDTO> dtos) throws SQLException {
    ArrayList<Horario> horarios = new ArrayList();
    for (HorarioDTO h : dtos) {
      horarios.add(new Horario(h));
    }
    return horarios;
  }
  */

  public void Save() throws SQLException {
    HorarioDTO dto = new HorarioDTO(-1, idMedico, dia, horaDesde, horaHasta);
    HorarioDAO dao = HorarioDAO.createDAO();
    id = dao.Save(dto);
  }

  public static String DeleteByMedicoID(int idMedico) {
    String err = null;
    try {
      HorarioDAO.createDAO().DeleteByMedicoID(idMedico);
    } catch (SQLException e) {
      err = e.getSQLState();
    }
    return err;
  }

  public static HorarioDTO SearchByID(int id) throws SQLException {
    HorarioDAO dao = HorarioDAO.createDAO();
    return dao.HorarioDTO(id);
  }

  public static ArrayList<HorarioDTO> SearchByMedicoID(int idMedico) throws SQLException {
    HorarioDAO dao = HorarioDAO.createDAO();
    return dao.SearchByMedicoID(idMedico);
  }

  public static ArrayList<HorarioDTO> SearchByDay(DayOfWeek day) throws SQLException {
    HorarioDAO dao = HorarioDAO.createDAO();
    return dao.SearchByDay(day);
  }

  public int getId() {
    return id;
  }

  public int getIdMedico() {
    return idMedico;
  }

  public DayOfWeek getDia() {
    return dia;
  }

  public LocalTime getHoraDesde() {
    return horaDesde;
  }

  public LocalTime getHoraHasta() {
    return horaHasta;
  }

}
